<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" id="d1">
<input type="button" value="添加帅哥" onclick="f(1)"><!--onclick="f1()-->
<input type="button" value="添加美女" onclick="f(2)"><!--onclick="f2()"-->

<script>
    /*我的逻辑*/
    /*    let d = document.querySelector("#d1");
    function f1() {
        for (let i = 0; i < d.value; i++) {
            let img = document.createElement("img");
            img.src = "../nv1.jpg";
            document.body.append(img);
        }
    }
    function f2() {
        for (let i = 0; i < d.value; i++) {
            let img =document.createElement("img");
            img.src="../wemen.jpg";
            document.body.append(img);
        }
    }*/
    //老师的逻辑
    let input = document.querySelector("#d1")
    function f(x) {
        let imgName = x==1?"nv1.jpg":"wemen.jpg";
        for (let i = 0; i <input.value ; i++) {
            let img= document.createElement("img");
            img.src=imgName;
            document.body.append(img);
        }
    }

</script>
</body>
</html>